/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package myfx.component;

import Globals.AllGlobal;
import brain.MyBrain;
import controller.MyController;
import database.operate.OperateMyDatabaseImpl;
import java.io.IOException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.stage.Modality;
import javafx.stage.Stage;
import model.ZuanKong_Model;

/**
 *
 * @author Administrator
 */
public class ZuanKong_Copy extends Stage{
    //
    private MyController controller;
    private ZuanKong_Model zuanKong_Model;
    private ZuanKong_Model zuanKong_info;
    //zuankonggeneral
    private MyBrain brain;
    TextFieldTreeCellImpl textFieldTreeCellImpl;
    private Scene scene ;
    private Group root=new Group();
    //方便填写数据
    final TextField konghaoField=new TextField();
    final TextField fangweiField=new TextField();
    final TextField qingjiaoField=new TextField(null);
    final TextField chengkongField=new TextField(null);
    final TextField zhujiangqianField=new TextField(null);
    final TextField shuiyaField=new TextField(null);
    final TextField kongshenField=new TextField(null);
    final TextField vField=new TextField(null);
    final TextField v2Field=new TextField(null);
    final TextField v3Field=new TextField(null);
    final TextField niantuField=new TextField(null);
    final TextField shuiniField=new TextField(null);
    final TextField zhongyaField=new TextField(null);
    final TextField beizhuField=new TextField(null);
    final TextField zuanchangField=new TextField();
    final TextField csdField=new TextField();
    private int drawType=AllGlobal.DRAW_ONE;
    public ZuanKong_Copy
            (MyController controller1,String zuanKongName,TextFieldTreeCellImpl textFieldTreeCellImpl,MyBrain brain,
            Stage owner, boolean modality, String title) 
            throws IOException, Exception{
        super();
        initOwner(owner);
        Modality m = modality ? Modality.APPLICATION_MODAL : Modality.NONE;
        initModality(m);
        setTitle(title);
        scene=new Scene(root, 500, 480, Color.WHITE);
        setScene(scene);
        MyCard mc1=new MyCard(490, 365, "量参调节",Color.DARKGRAY);
        mc1.setTranslateX(5);
        mc1.setTranslateY(5);
        root.getChildren().add(mc1);
        MyCard mc2=new MyCard(490, 30, "输入处理",Color.DARKGRAY);
        mc2.setTranslateX(5);
        mc2.setTranslateY(395);
        root.getChildren().add(mc2);
        this.textFieldTreeCellImpl=textFieldTreeCellImpl;
        
        this.brain=brain;
        //钻孔model初始化
        zuanKong_Model=new ZuanKong_Model();
    	this.controller=controller1;
        this.setResizable(false);
        createScene();
        ArrayList<ZuanKong_Model> zkms;
        if((zkms=OperateMyDatabaseImpl.getOne(AllGlobal.ZUANKONG_SQL, 
            "select * from zuankong where mingcheng='"+textFieldTreeCellImpl.getTreeItem().getValue()+"';"
           )).isEmpty()){
            //controller.getJmeCanvas().setZuanKong(zuanKong_Model,AllGlobal.DRAW_ONE);
            zuanKong_info=new ZuanKong_Model();
        }   
        else{
            //controller.getJmeCanvas().setZuanKong(zuanKong_Model,AllGlobal.UPDATE_ONE);
            drawType=AllGlobal.UPDATE_ONE;
            zuanKong_info=zkms.get(0);
            konghaoField.setText(zuanKong_info.getMingcheng());
            fangweiField.setText(zuanKong_info.getFangwei());
            qingjiaoField.setText(zuanKong_info.getQingjiao());
            chengkongField.setText(zuanKong_info.getChengkong());
            zhujiangqianField.setText(zuanKong_info.getZhujiangqian());
            shuiyaField.setText(zuanKong_info.getShuiya());
            kongshenField.setText(zuanKong_info.getKongshen());
            vField.setText(zuanKong_info.getVa());
            v2Field.setText(zuanKong_info.getVb());
            v3Field.setText(zuanKong_info.getVc());
            niantuField.setText(zuanKong_info.getNiantu());
            shuiniField.setText(zuanKong_info.getShuini());
            zhongyaField.setText(zuanKong_info.getZhongya());
            beizhuField.setText(zuanKong_info.getBeizhu());
            zuanchangField.setText(zuanKong_info.getZuanchang());
            csdField.setText(zuanKong_info.getChushuidianshuipingtouying());
         }
    }

    private void createScene() throws IOException {
       //warning
        final Text warningText=new Text("钻孔数据信息显示");
        warningText.setFill(Color.GREEN);
        warningText.setFont(new Font(18));
        warningText.setTranslateX(15);
        warningText.setTranslateY(460);
        root.getChildren().add(warningText);
        
        Text khText=new Text("钻孔名称");
        
        konghaoField.setText("");
        konghaoField.setPromptText("请输入钻孔名称");
        konghaoField.setPrefSize(150, 12);
        konghaoField.setTranslateX(80);
        konghaoField.setTranslateY(40);
        khText.setTranslateX(15);
        khText.setTranslateY(55);
        root.getChildren().add(konghaoField);
        root.getChildren().add(khText);
        Text fwText=new Text("方位角");

        fangweiField.setPromptText("请输入方位角");
        fangweiField.setPrefSize(150, 12);
        fangweiField.setTranslateX(80);
        fangweiField.setTranslateY(63);
        fwText.setTranslateX(15);
        fwText.setTranslateY(78);
        root.getChildren().add(fangweiField);
        root.getChildren().add(fwText);
        Text qjText=new Text("倾角");

        qingjiaoField.setPromptText("请输入倾角角度");
        qingjiaoField.setPrefSize(150, 12);
        qingjiaoField.setTranslateX(315);
        qingjiaoField.setTranslateY(63);
        qjText.setTranslateX(250);
        qjText.setTranslateY(78);
        root.getChildren().add(qingjiaoField);
        root.getChildren().add(qjText);
        Text xxtsText=new Text("提示：下述两个为水量,单位M³/H");
        xxtsText.setFill(Color.YELLOW);
        xxtsText.setTranslateX(15);
        xxtsText.setTranslateY(101);
        root.getChildren().add(xxtsText);
        Text ckText=new Text("成孔");
        
        chengkongField.setPromptText("请输入成孔水量M³/H");
        chengkongField.setPrefSize(150, 12);
        chengkongField.setTranslateX(80);
        chengkongField.setTranslateY(109);
        ckText.setTranslateX(15);
        ckText.setTranslateY(124);
        root.getChildren().add(chengkongField);
        root.getChildren().add(ckText);
        Text zjqText=new Text("注浆前");
        
        zhujiangqianField.setPromptText("请输入注浆前水量M³/H");
        zhujiangqianField.setPrefSize(150, 12);
        zhujiangqianField.setTranslateX(315);
        zhujiangqianField.setTranslateY(109);
        zjqText.setTranslateX(250);
        zjqText.setTranslateY(124);
        root.getChildren().add(zhujiangqianField);
        root.getChildren().add(zjqText);
        Text syText=new Text("水压");
        
        shuiyaField.setPromptText("请输入水压MPa");
        shuiyaField.setPrefSize(150, 12);
        shuiyaField.setTranslateX(80);
        shuiyaField.setTranslateY(132);
        syText.setTranslateX(15);
        syText.setTranslateY(147);
        root.getChildren().add(shuiyaField);
        root.getChildren().add(syText);
        Text ksText=new Text("孔深");
        
        kongshenField.setPromptText("请输入注浆孔深m");
        kongshenField.setPrefSize(150, 12);
        kongshenField.setTranslateX(315);
        kongshenField.setTranslateY(132);
        ksText.setTranslateX(250);
        ksText.setTranslateY(147);
        root.getChildren().add(kongshenField);
        root.getChildren().add(ksText);
        Text zjtjvxxtsText=new Text("提示:V1粘土水泥浆，V2水泥浆，V3纯粘土浆");
        zjtjvxxtsText.setFill(Color.YELLOW);
        zjtjvxxtsText.setTranslateX(15);
        zjtjvxxtsText.setTranslateY(170);
        root.getChildren().add(zjtjvxxtsText);
        Text V1Text=new Text("V1");
        
        vField.setPromptText("请输入V1");
        vField.setPrefSize(150, 12);
        vField.setTranslateX(80);
        vField.setTranslateY(178);
        V1Text.setTranslateX(15);
        V1Text.setTranslateY(193);
        root.getChildren().add(vField);
        root.getChildren().add(V1Text);
        Text V2Text=new Text("V2");
        
        v2Field.setPromptText("请输入V2");
        v2Field.setPrefSize(150, 12);
        v2Field.setTranslateX(315);
        v2Field.setTranslateY(178);
        V2Text.setTranslateX(250);
        V2Text.setTranslateY(193);
        root.getChildren().add(v2Field);
        root.getChildren().add(V2Text);
        Text V3Text=new Text("V3");
        
        v3Field.setPromptText("请输入V3");
        v3Field.setPrefSize(150, 12);
        v3Field.setTranslateX(80);
        v3Field.setTranslateY(201);
        V3Text.setTranslateX(15);
        V3Text.setTranslateY(216);
        root.getChildren().add(v3Field);
        root.getChildren().add(V3Text);
        Text ntText=new Text("粘土");
        
        niantuField.setPromptText("请输入粘土量 吨");
        niantuField.setPrefSize(150, 12);
        niantuField.setTranslateX(80);
        niantuField.setTranslateY(224);
        ntText.setTranslateX(15);
        ntText.setTranslateY(239);
        root.getChildren().add(niantuField);
        root.getChildren().add(ntText);
        Text snText=new Text("水泥");
        
        shuiniField.setPromptText("请输入水泥量 吨");
        shuiniField.setPrefSize(150, 12);
        shuiniField.setTranslateX(315);
        shuiniField.setTranslateY(224);
        snText.setTranslateX(250);
        snText.setTranslateY(239);
        root.getChildren().add(shuiniField);
        root.getChildren().add(snText);
        Text zyText=new Text("终压");
        
        zhongyaField.setPromptText("请输入终压MPa");
        zhongyaField.setPrefSize(150, 12);
        zhongyaField.setTranslateX(80);
        zhongyaField.setTranslateY(247);
        zyText.setTranslateX(15);
        zyText.setTranslateY(262);
        root.getChildren().add(zhongyaField);
        root.getChildren().add(zyText);
        Text bzText=new Text("备注");
        
        beizhuField.setPromptText("请输入备注");
        beizhuField.setPrefSize(385, 12);
        beizhuField.setTranslateX(80);
        beizhuField.setTranslateY(270);
        bzText.setTranslateX(15);
        bzText.setTranslateY(285);
        root.getChildren().add(beizhuField);
        root.getChildren().add(bzText);
        Text zcText=new Text("钻场");
        
        zuanchangField.setText(textFieldTreeCellImpl.getTreeItem().getParent().getValue());
        zuanchangField.setPrefSize(150, 12);
        zuanchangField.setTranslateX(80);
        zuanchangField.setTranslateY(293);
        zuanchangField.setDisable(true);
        zcText.setTranslateX(15);
        zcText.setTranslateY(308);
        root.getChildren().add(zuanchangField);
        root.getChildren().add(zcText);
        Text csdText=new Text("注意：出水点距钻眼出的距离在平行于煤层平面的投影");
        csdText.setFill(Color.RED);
        csdText.setTranslateX(15);
        csdText.setTranslateY(331);
        root.getChildren().add(csdText);
        Text csdText1=new Text("出水点");
        
        csdField.setPromptText("出水点水平投影距离");
        csdField.setPrefSize(150, 12);
        csdField.setTranslateX(80);
        csdField.setTranslateY(339);
        csdText1.setTranslateX(15);
        csdText1.setTranslateY(354);
        root.getChildren().add(csdField);
        root.getChildren().add(csdText1);
        //创建提交处理
        Button ok=new Button("确      认");
        Button retry=new Button("重新输入");
        ok.setTranslateX(170);
        ok.setTranslateY(422);       
        retry.setTranslateX(250);
        retry.setTranslateY(422);
        root.getChildren().add(ok);
        root.getChildren().add(retry);
        
        //事件处理
        ok.setOnAction(new EventHandler<ActionEvent>() {

            public void handle(ActionEvent t) {
                try {
                    ArrayList<ZuanKong_Model> zkms;
                    if((zkms=OperateMyDatabaseImpl.getOne(AllGlobal.ZUANKONG_SQL, 
                        "select * from zuankong where mingcheng='"+textFieldTreeCellImpl.getTreeItem().getValue()+"';"
                       )).isEmpty()){
                        drawType=AllGlobal.DRAW_ONE;
                    }   
                    else{
                        //controller.getJmeCanvas().setZuanKong(zuanKong_Model,AllGlobal.UPDATE_ONE);
                        drawType=AllGlobal.UPDATE_ONE;
                     }
                    zuanKong_Model.setMingcheng(konghaoField.getText());
                    zuanKong_Model.setFangwei(fangweiField.getText());
                    zuanKong_Model.setQingjiao(qingjiaoField.getText());
                    zuanKong_Model.setChengkong(chengkongField.getText());
                    zuanKong_Model.setZhujiangqian(zhujiangqianField.getText());
                    zuanKong_Model.setShuiya(shuiyaField.getText());
                    zuanKong_Model.setKongshen(kongshenField.getText());
                    zuanKong_Model.setVa(vField.getText());
                    zuanKong_Model.setVb(v2Field.getText());
                    zuanKong_Model.setVc(v3Field.getText());
                    zuanKong_Model.setNiantu(niantuField.getText());
                    zuanKong_Model.setShuini(shuiniField.getText());
                    zuanKong_Model.setZhongya(zhongyaField.getText());
                    zuanKong_Model.setBeizhu(beizhuField.getText());
                    zuanKong_Model.setZuanchang(textFieldTreeCellImpl.getTreeItem().getParent().getValue());
                    zuanKong_Model.setChushuidianshuipingtouying(csdField.getText());
                    
                        
                    //INSERT INTO 表名称 VALUES (值1, 值2,....)
                    if(drawType==AllGlobal.DRAW_ONE){
                        OperateMyDatabaseImpl.doAdd("insert into zuankong values ('"+
                                zuanKong_Model.getMingcheng()+"','"+
                                zuanKong_Model.getFangwei()+"','"+
                                zuanKong_Model.getQingjiao()+"','"+
                                zuanKong_Model.getChengkong()+"','"+
                                zuanKong_Model.getZhujiangqian()+"','"+
                                zuanKong_Model.getShuiya()+"','"+
                                zuanKong_Model.getKongshen()+"','"+
                                zuanKong_Model.getVa()+"','"+
                                zuanKong_Model.getVb()+"','"+
                                zuanKong_Model.getVc()+"','"+
                                zuanKong_Model.getNiantu()+"','"+
                                zuanKong_Model.getShuini()+"','"+
                                zuanKong_Model.getZhongya()+"','"+
                                zuanKong_Model.getBeizhu()+"','"+
                                zuanKong_Model.getZuanchang()+"','"+
                                zuanKong_Model.getChushuidianshuipingtouying()+
                                "');");
                        warningText.setText("成功插入数据");
                    }
                    else{
                        OperateMyDatabaseImpl.doUpdate("update zuankong set "+
                                "mingcheng='"+zuanKong_Model.getMingcheng()+"',"+
                                "fangwei='"+zuanKong_Model.getFangwei()+"',"+
                                "qingjiao='"+zuanKong_Model.getQingjiao()+"',"+
                                "chengkong='"+zuanKong_Model.getChengkong()+"',"+
                                "zhujiangqian='"+zuanKong_Model.getZhujiangqian()+"',"+
                                "shuiya='"+zuanKong_Model.getShuiya()+"',"+
                                "kongshen='"+zuanKong_Model.getKongshen()+"',"+
                                "va='"+zuanKong_Model.getVa()+"',"+
                                "vb='"+zuanKong_Model.getVb()+"',"+
                                "vc='"+zuanKong_Model.getVc()+"',"+
                                "niantu='"+zuanKong_Model.getNiantu()+"',"+
                                "shuini='"+zuanKong_Model.getShuini()+"',"+
                                "zhongya='"+zuanKong_Model.getZhongya()+"',"+
                                "beizhu='"+zuanKong_Model.getBeizhu()+"',"+
                                "zuanchang='"+zuanKong_Model.getZuanchang()+"',"+
                                "csdjl='"+zuanKong_Model.getChushuidianshuipingtouying()+"'"+
                                " where mingcheng='"+zuanKong_Model.getMingcheng()+"';");
                    }
                    textFieldTreeCellImpl.getTreeItem().setValue(konghaoField.getText());
                    warningText.setText("成功修改数据");
                } catch (Exception ex) {
                    Logger.getLogger(ZuanKong_Copy.class.getName()).log(Level.SEVERE, null, ex);
                    warningText.setText("数据修改失败");
                }
            }
        });
        retry.setOnAction(new EventHandler<ActionEvent>() {

            public void handle(ActionEvent t) {
                konghaoField.setText(zuanKong_info.getMingcheng());
                fangweiField.setText(zuanKong_info.getFangwei());
                qingjiaoField.setText(zuanKong_info.getQingjiao());
                chengkongField.setText(zuanKong_info.getChengkong());
                zhujiangqianField.setText(zuanKong_info.getZhujiangqian());
                shuiyaField.setText(zuanKong_info.getShuiya());
                kongshenField.setText(zuanKong_info.getKongshen());
                vField.setText(zuanKong_info.getVa());
                v2Field.setText(zuanKong_info.getVb());
                v3Field.setText(zuanKong_info.getVc());
                niantuField.setText(zuanKong_info.getNiantu());
                shuiniField.setText(zuanKong_info.getShuini());
                zhongyaField.setText(zuanKong_info.getZhongya());
                beizhuField.setText(zuanKong_info.getBeizhu());
                zuanchangField.setText(zuanKong_info.getZuanchang());
                csdField.setText(zuanKong_info.getChushuidianshuipingtouying());
                warningText.setText("重新输入数据");
            }
        });
    }

}
